package com.example.mobileshop.utils;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;

public class HttpHandler{
	private HttpClient httpClient = new DefaultHttpClient();
	
	public HttpResponse postRequestWithParams(String url,List<NameValuePair> nameValuePairs){
		HttpPost httpPost = new HttpPost(url);	
		HttpResponse response = null;
		try {			
			HttpEntity entity;				        
			entity = new UrlEncodedFormEntity(nameValuePairs);			
			httpPost.setEntity(entity);					    			
		    response = httpClient.execute(httpPost);					    		    
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();					    
		} catch(Exception e) {
			e.printStackTrace();
		}	
		return response;		
	}
}